﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebStore.Web.App.Models.Account;
using WebStore.Web.App.Utility.Enum;

namespace WebStore.Web.App.Controllers
{
    public partial class AccountController
    {
        public ViewResult Register()
        {
            return View(new RegisterModel());
        }
        
        [HttpPost]
        [ActionName("Register")]
        public ActionResult RegisterPost()
        {
            var model = new RegisterModel();
            if (!TryUpdateModel(model) || !ModelState.IsValid)
                return View(model);
            string errorMessage;
             
            if (!_accountService.Register(model.Email, model.Password, out errorMessage))
            {
                ModelState.AddModelError("", errorMessage);
                return View(model);
            }
            CreateMessage("You have succesfully created your account", ClientMessageType.Information);
            return RedirectToAction("Index","Home");
        }
    }
}